/**
 * Urban Parks
 *
 * Team M&M's:
 * Michael Satran Jr
 * Michael Pogson
 * Stephen Hunter
 *
 * Date: 2/16/2012
 */
package view;

import model.ParkManager;
import model.StaffMember;
import model.User;
import model.Volunteer;
import controller.Controller;

/**
 * This class acts as a controller for the GUI panels.
 * 
 * @author Michael Satran Jr
 */
public class GUI {
	
	/**
	 * Array index for my_panels which points to the SigninPanel
	 */
	private static final int MY_SIGNIN_MASK = 0;
	/**
	 * Array index for my_panels which points to the VolunteerPanel
	 */
	private static final int MY_VOLUNTEER_MASK = 1;
	/**
	 * Array index for my_panels which points to the StaffPanel
	 */
	private static final int MY_STAFF_MASK = 2;
	/**
	 * Array index for my_panels which points to the ParkManagerPanel
	 */
	private static final int MY_PARK_MANAGER_MASK = 3;
	
	/**
	 * Reference to the controller.
	 */
	protected final Controller my_controller;
	/**
	 * Reference to the user who wants to sign in.
	 */
	private int my_user;
	
	/**
	 * Contains all the users' panels.
	 */
	private final UserPanel[] my_panels;
	
	/**
	 * Constructs a new GUI
	 * @param the_controller The controller to use with the GUI.
	 */
	public GUI(Controller the_controller) {
		my_controller = the_controller;
		
		my_panels = new UserPanel[4];
		
		my_panels[MY_SIGNIN_MASK] = new SigninPanel(this);
		my_panels[MY_VOLUNTEER_MASK] = new VolunteerPanel(my_controller);
		my_panels[MY_STAFF_MASK] = new StaffPanel(my_controller);
		my_panels[MY_PARK_MANAGER_MASK] = new ParkManagerPanel(my_controller);
		
		my_user = 0;
	}
	
	/**
	 * Starts the SigninPanel.
	 */
	public void start() {
		//Start the sign in panel.
		my_panels[MY_SIGNIN_MASK].setup();
		my_panels[MY_SIGNIN_MASK].start();
	}
	
	/**
	 * Shows the panel for the user specified.
	 * @param the_user The User to show the panel for.
	 */
	protected void showPanel(User the_user) {
		
		//Uses instance of to check which panel to show and set the user pointer to it's panel
		if (the_user instanceof StaffMember) {
			my_user = MY_STAFF_MASK;
		}else if (the_user instanceof Volunteer) {
			my_user = MY_VOLUNTEER_MASK;
		} else if (the_user instanceof ParkManager) {
			my_user = MY_PARK_MANAGER_MASK;
		}
		
		//User the user pointer to decode which panel to show.
		my_panels[my_user].setup();
		my_panels[my_user].start();
	}
	
}
